package top.hkyzf.study.leetcode.math;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-2-25 8:59
 */
public class 复数乘法_537 {
    public String complexNumberMultiply(String num1, String num2) {
        String[] na = num1.split("\\+");
        int na1 = Integer.parseInt(na[0]);
        int na2 = 1;
        if (!na[1].equals("i")) {
            na2 = Integer.parseInt(na[1].replace("i", ""));
        }
        String[] nb = num2.split("\\+");
        int nb1 = Integer.parseInt(nb[0]);
        int nb2 = 1;
        if (!nb[1].equals("i")) {
            nb2 = Integer.parseInt(nb[1].replace("i", ""));
        }
        int nr1 = na1 * nb1 + na2 * nb2 * -1;
        int nr2 = na1 * nb2 + na2 * nb1;
        return nr1 + "+" + nr2 + "i";
    }

    @Test
    public void testComplexNumberMultiply () {
        String num1 = "1+-1i";
        String num2 = "0+0i";
        System.out.println(complexNumberMultiply(num1, num2));
    }
}
